﻿/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;

namespace DaveSexton.DocProject.Sandcastle
{
	[Serializable]
	[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1724:TypeNamesShouldNotMatchNamespaces")]
	public struct Metadata : IEquatable<Metadata>
	{
		#region Public Properties
		public static readonly Metadata Empty = new Metadata();

		public string Name
		{
			get
			{
				return name;
			}
		}

		public string Value
		{
			get
			{
				return value;
			}
		}
		#endregion

		#region Private / Protected
		private readonly string name, value;
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="Metadata" /> structure.
		/// </summary>
		public Metadata(string name, string value)
		{
			this.name = name;
			this.value = value;
		}
		#endregion

		#region Methods
		public override bool Equals(object obj)
		{
			return obj is Metadata && Equals((Metadata) obj);
		}

		public bool Equals(Metadata other)
		{
			return string.Equals(name ?? "", other.name ?? "", StringComparison.OrdinalIgnoreCase)
				&& string.Equals(value ?? "", other.value ?? "", StringComparison.OrdinalIgnoreCase);
		}

		public override int GetHashCode()
		{
			return (name ?? "").GetHashCode() ^ (value ?? "").GetHashCode();
		}

		public override string ToString()
		{
			return "{" + name + ", " + value + "}";
		}
		#endregion

		#region Operator Overloads
		public static bool operator ==(Metadata data1, Metadata data2)
		{
			return data1.Equals(data2);
		}

		public static bool operator !=(Metadata data1, Metadata data2)
		{
			return !data1.Equals(data2);
		}
		#endregion
	}
}
